//
//  DZToolbox.h
//  ZhaoJin
//
//  Created by Darren on 15/5/2.
//  Copyright (c) 2015年 Darren Zheng. All rights reserved.
//

#import <UIKit/UIKit.h>

////////////////////////////////////////////////////////////
// 快捷访问
////////////////////////////////////////////////////////////

#define APP_DELEGATE ((AppDelegate *)([UIApplication sharedApplication].delegate))
#define APP_WINDOW [[[UIApplication sharedApplication] delegate] window]

////////////////////////////////////////////////////////////
// 设备
////////////////////////////////////////////////////////////

#define UMSYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define  DEVICE_SYSTEM_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue] >=9.0)

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

////////////////////////////////////////////////////////////
// 颜色
////////////////////////////////////////////////////////////

#define UIColorFromRGB(rgbValue)	[UIColor colorWithRed:((float)(((rgbValue) & 0xFF0000) >> 16))/255.0 \
green:((float)(((rgbValue) & 0x00FF00) >> 8))/255.0 \
blue:((float)((rgbValue) & 0x0000FF))/255.0 \
alpha:1.0]

#define UIColorFromRGBA(rgbValue, alphaValue)		[UIColor colorWithRed:((float)(((rgbValue) & 0xFF0000) >> 16))/255.0 \
green:((float)(((rgbValue) & 0x00FF00) >> 8))/255.0 \
blue:((float)((rgbValue) & 0x0000FF))/255.0 \
alpha:(alphaValue)]

#define RGBA(r, g, b, a)                    [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r, g, b)                        RGBA(r, g, b, 1.0f)

////////////////////////////////////////////////////////////
// UI
////////////////////////////////////////////////////////////

#define SetX(frame, x)               frame = CGRectMake(x, frame.origin.y, frame.size.width, frame.size.height)
#define SetY(frame, y)               frame = CGRectMake(frame.origin.x, y, frame.size.width, frame.size.height)
#define SetWidth(frame, w)           frame = CGRectMake(frame.origin.x, frame.origin.y, w, frame.size.height)
#define SetHeight(frame, h)          frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, h)
#define SetOrigin(frame, x, y)       frame = CGRectMake(x, y, frame.size.width, frame.size.height)
#define SetSize(frame, w, h)         frame = CGRectMake(frame.origin.x, frame.origin.y, w, h)
#define SetFrame(frame, x, y, w, h)  frame = CGRectMake(x, y, w, h)
#define AddX(frame, offset)          frame = CGRectMake(frame.origin.x + offset, frame.origin.y, frame.size.width, frame.size.height)
#define AddY(frame, offset)          frame = CGRectMake(frame.origin.x, frame.origin.y + offset, frame.size.width, frame.size.height)
#define AddHeight(frame, offset)     frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height+offset)
#define AddWidth(frame, offset)      frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width+offset, frame.size.height)
#define X(frame)                     frame.origin.x
#define Y(frame)                     frame.origin.y
#define Width(frame)                 frame.size.width
#define Height(frame)                frame.size.height
#define Origin(frame)                frame.origin
#define Size(frame)                  frame.size
#define SetCenterX(center, x)        center = CGPointMake(x, center.y)
#define SetCenterY(center, y)        center = CGPointMake(center.x, y)
#define MaxY(frame)                  CGRectGetMaxY(frame)
#define MaxX(frame)                  CGRectGetMaxX(frame)
#define LogRect(frame)              NSLog(@"x(%.2f), y(%.2f), w(%.2f), h(%.2f)",frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)
#define SetBorder(view, color)      view.layer.borderColor = [color CGColor]; view.layer.borderWidth = 1
#define SetBorderBlack(view)      view.layer.borderColor = [[UIColor blackColor] CGColor]; view.layer.borderWidth = 1

@interface DZUtility : NSObject


NSString *stringDataWithTimeInterval(int timerInterval);//返回时间格式2015-10-10

NSString *stringYearDataWithTimeInterval(int timerInterval);//返回时间格式2015年10月10日

@end
